let fs = require('fs');

let base_url = "https://gitee.com/songbai_x/bqb_static/raw/master/";
let path = base_url + "files/images_template/"

fs.readFile("../db/image_template.json", function (err, data) {
  if (err) {
    console.log(err)
  }
  data = data.toString()
  let json = JSON.parse(data)
  let type = {}

  json.data.map(e => {
    if (!type[e.type_id]) {
      type[e.type_id] = []
    }
    e.url = path + e.url
    type[e.type_id].push(e)
  })

  for (const key in type) {
    let str = JSON.stringify(type[key]);
    fs.writeFile(`../db/image_template_type/${key}.json`, str, function (err) {
      if (err) {
        console.error(err);
      }
      console.log('----------分类创建成功-------------');
    })
  }

})